package com.synnex.mobile.servier.core.content.service.impl;

import com.synnex.mobile.generic.core.util.ObjectUtil;
import com.synnex.mobile.servier.core.content.bo.ContentBo;
import com.synnex.mobile.servier.core.content.dao.ContentDao;
import com.synnex.mobile.servier.core.content.dto.Content;
import com.synnex.mobile.servier.core.content.service.ContentService;
import com.synnex.mobile.servier.core.service.impl.AbstractServiceImpl;
import com.synnex.mobile.servier.web.utils.DateUtil;
import org.apache.commons.httpclient.util.DateParseException;
import org.springframework.transaction.annotation.Transactional;

import java.text.ParseException;
import java.util.Date;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: kerryf
 * To change this template use File | Settings | File Templates.
 */
@Transactional
public class ContentServiceImpl extends AbstractServiceImpl implements ContentService {

    protected ContentDao contentDao;

    public void setContentDao(ContentDao contentDao) {
        this.contentDao = contentDao;
    }

    public ContentBo getCompanyIntro() {

        Content introduce= contentDao.getCompanyIntro();
        ContentBo bo = ObjectUtil.copyProperties(introduce,ContentBo.class);
        return bo;
    }

    public ContentBo getContentById(Integer id) {

        Content content = contentDao.getContentById(id);
        return ContentBo.createInstance(content);
    }

    public List<ContentBo> getMeetRoundByType(String type) {

        List<Content> meetRounds = contentDao.getContentByType(type);
        return ContentBo.createInstance(meetRounds);
    }

    public List<ContentBo> getContent() {
        List<Content> contents = contentDao.getContent();
        return ContentBo.createInstance(contents);
    }

    public List<ContentBo> getSessionByGroup(Integer groupId) {

        List<Content> meetRounds = contentDao.getContentByGroup(groupId);
        return ContentBo.createInstance(meetRounds);
    }

    public List<ContentBo> getSessionByDayAndSection(String date, String section) throws ParseException {

        Date date1 = null;
        if(null != date && !date.equals("")){
            date1 = DateUtil.strToDate(date.trim(),"MM-dd-yyyy");
        }

        List<Content> sessions = contentDao.getSessionByDayAndSection(date1,section);
//        List<Groups> groupList = contentDao.getGroupList();
        return ContentBo.createInstance(sessions);
    }

    public void addContent(ContentBo bo) {

        Content content  = ObjectUtil.copyProperties(bo,Content.class);
        content.setEntryDate(new Date());

        contentDao.saveContent(content);
    }

    public void editContent(ContentBo bo) {
        Content content  = ObjectUtil.copyProperties(bo,Content.class);
        content.setUpdateDate(new Date());

        contentDao.editContent(content);
    }

    public List<ContentBo> getContentByType(String type) {
        List<Content> data = contentDao.getContentByType(type);
        return ContentBo.createInstance(data);
    }

    public void deleteContentById(int id) {
        contentDao.deleteContentById(id);
    }


}
